using System;
using System.Collections.Generic;
using UnityEngine;

namespace Features
{
    [CreateAssetMenu(fileName = "Sweep", menuName = "Features/横扫", order = 5)]
    public class Sweep : Feature
    {
        public override void CancleEffect(FeatureEventArgs args)
        {

        }

        public override void ExecuteEffect(FeatureEventArgs args)
        {
            foreach (var defencer in args.Defencer)
            {
                int layer = defencer.gridNode.layer;
                int left = defencer.gridNode.number - 1;
                int right = defencer.gridNode.number + 1;

                var leftNode = GridManager.instance.GetGridNode(layer, left);
                var rightNode = GridManager.instance.GetGridNode(layer, right);

                SpriteTextManager.NewEffectText("横扫", args.Attacker.transform.position.x, args.Attacker.transform.position.y, Color.red);
                if (leftNode != null && leftNode.Pawn != null)
                    leftNode?.Pawn.BeHit(args.Attacker.Property.Attack, args.Attacker);
                if (rightNode != null && rightNode.Pawn != null)
                    rightNode?.Pawn.BeHit(args.Attacker.Property.Attack, args.Attacker);
            }
        }

        public override string GetDescription()
        {
            return "同时打击相邻目标";
        }
    }
}